package org.szy.plugin.dev.pojo;

import cn.hutool.core.convert.Convert;
import org.szy.core.common.entity.TreeSelect;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 主系统树结构实体类
 *
 * @author 孙志阳
 * @date 2021-11-01
 * @since 2.0.0
 **/
public class DevAreaTreeOption extends TreeSelect {

    private Integer level;

    public DevAreaTreeOption(DevAreaTree entity) {
        this.setId(Convert.toStr(entity.getId()));
        this.setSpareId(entity.getPid() + "");
        this.setLabel(entity.getName());
        this.setValue(this.getId());
        this.setLevel(entity.getLevel());
        if (entity.getChildren() == null || entity.getChildren().isEmpty()) {
            this.setChildren(null);
        } else {
            this.setChildren(entity.getChildren().stream().map(DevAreaTreeOption::new).collect(Collectors.toList()));
        }
    }

    public static List<DevAreaTreeOption> buildTreeOption(List<DevAreaTree> trees) {
        return trees.stream().map(DevAreaTreeOption::new).collect(Collectors.toList());
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public Integer getLevel() {
        return level;
    }

}
